/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.graficaluna.dao.otros;

import dto.MaquinaDTO;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 *
 * @author ralf
 */
public class MaquinaDAO {
     private SqlSessionFactory sqlSessionFactory;

    public MaquinaDAO() {
        sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
    }
    
    
    public List<MaquinaDTO> listarMaquinas() throws Exception{
        SqlSession session = sqlSessionFactory.openSession();
        try {
            List<MaquinaDTO> list = session.selectList("maquinaSQL.listarMaquinas");            
            return list;
        }catch(Exception e){                       
            throw new Exception(e.getMessage());
        } finally {
            session.close();
        }
    }
    
     public List<MaquinaDTO> listarMaquinasPorCarrera(MaquinaDTO maquina) throws Exception{
        SqlSession session = sqlSessionFactory.openSession();
        try {
            List<MaquinaDTO> list = session.selectList("maquinaSQL.listarMaquinasPorCarrera",maquina);            
            return list;
        }catch(Exception e){                       
            throw new Exception(e.getMessage());
        } finally {
            session.close();
        }
    }
     
     public void actualizarAsignacionMaquina(MaquinaDTO maquina) throws Exception{
        SqlSession session = sqlSessionFactory.openSession(false);
        try {
           session.update("maquinaSQL.actualizarAsignacionMaquina",maquina);
           session.commit();
        }catch(Exception e){                       
            throw new Exception(e.getMessage());
        } finally {
            session.close();
        }
    }
}
